window.onload = function() {
    var regphone = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
    var regmsg = /^\d{6}$/;
    var regpsw = /^[a-zA-Z0-9_-]{6,16}$/;
    var phone = document.querySelector('#phone');
    var msg = document.querySelector('#msg');
    var psw = document.querySelector('#psw');
    var surepsw = document.querySelector('#surepsw');
    regLogin(phone, regphone);
    regLogin(msg, regmsg);
    regLogin(psw, regpsw);


    function regLogin(ele, reg) {
        ele.onblur = function() {
            if (reg.test(this.value)) {
                this.nextElementSibling.className = 'success';
                this.nextElementSibling.innerHTML = '<i class="successicon"></i> 格式正确';
            } else {
                this.nextElementSibling.className = 'error';
                this.nextElementSibling.innerHTML = '<i class="erroricon"></i> 格式不正确，请重新输入';
            }
        }
    }

    surepsw.onblur = function() {
        if (this.value == psw.value) {
            console.log('true');
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = '<i class="successicon"></i> 密码一致';
        } else {
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = '<i class="erroricon"></i> 密码不一致';
        }
    }
}